/*************************************************************************
    > File Name: list.c
    > Author: kayshi
    > Mail: kayshi2019@qq.com
    > Created Time: Fri 30 Oct 2020 11:28:54 AM CST
 ************************************************************************/

#include <stdio.h>
#include <string.h>

#include "list.h"

#define MAX_NAME_LEN 32
#define MAX_ID_LEN 10

typedef struct stud
{   
    struct list_head list;
    char name[MAX_NAME_LEN];
    char stu_number[MAX_ID_LEN];
}num_n_stu;

typedef struct stud_1
{
    struct list_head list;
    char name[MAX_NAME_LEN];
    char stu_number[MAX_ID_LEN];
    char id; 
}num_n_stu1;

int main(void)
{
    struct list_head head;
    num_n_stu stu_1;
    num_n_stu stu_2;
    num_n_stu1 stu_x;
    num_n_stu *entry;

    struct list_head *p; 
    INIT_LIST_HEAD(&head);
    strcpy(stu_1.name, "lisi");
    strcpy(stu_1.stu_number, "10000000");
        strcpy(stu_2.name, "kay");
    strcpy(stu_2.stu_number, "10000001");
    strcpy(stu_x.name, "yan");
    strcpy(stu_x.stu_number, "10000002");

    list_add(&stu_1.list, &head);
    list_add(&stu_2.list, &head);
    list_add(&stu_x.list, &head);
    //list_del(&stu_2.list);
    list_for_each(p, &head)
    {
        entry= list_entry(p, struct stud, list);
        printf("name:%s\n", entry->name);
        printf("stu_number:%s\n", entry->stu_number);
    }
    list_del(&stu_1.list);
    return 0;
}


/*

    结果打印:
    kayshi@ubuntu:~/code/list$ ./a.out 
    name:yan
    stu_number:10000002
    name:kay
    stu_number:10000001
    name:lisi
    stu_number:10000000
    kayshi@ubuntu:~/code/list$ 

    list_add 从头部加
    list_add_tail 从尾部加
*/